package com.csthink.auditlog.dto;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

/**
 * Page Result Container.
 * When we query by ES, one single query will get both count and results.
 * We should not divide these two process for performance consideration.
 *
 * @author <a href="mailto:security.2009@live.cn">Mars</a>
 * @since 2023-09-12
 */
@Getter
@Setter
@NoArgsConstructor
public class PageResultDTO<T> {

    private Integer pageNumber;
    private Integer pageSize;
    private Integer pageTotal;
    private Integer recordsTotal;
    private List<T> records;

    // Previous page token
    private String prev;
    // Next page token
    private String next;

    public PageResultDTO(Integer pageNumber, Integer pageSize, Integer pageTotal, Integer recordsTotal, List<T> records) {
        this.pageNumber = pageNumber;
        this.pageSize = pageSize;
        this.pageTotal = pageTotal;
        this.recordsTotal = recordsTotal;
        this.records = records;
    }

    public PageResultDTO(Integer pageNumber, Integer pageSize, Integer pageTotal, Integer recordsTotal, List<T> records, String prev, String next) {
        this.pageNumber = pageNumber;
        this.pageSize = pageSize;
        this.pageTotal = pageTotal;
        this.recordsTotal = recordsTotal;
        this.records = records;
        this.prev = prev;
        this.next = next;
    }
}
